package cn.tedu.egaddress0904.Controller;


import cn.tedu.egaddress0904.Mapper.Egaddressmapper;
import cn.tedu.egaddress0904.pojo.dto.AddressAddParam;
import cn.tedu.egaddress0904.pojo.entity.egaddress;
import cn.tedu.egaddress0904.pojo.vo.AddressListVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/address")
public class egaddresscontroller {
    @Autowired
    private Egaddressmapper egaddressmapper;
    @PostMapping("/add")
    public String add(@RequestBody AddressAddParam address){
        System.out.println("address = " + address);
        egaddress egaddress = new egaddress();
        BeanUtils.copyProperties(address,egaddress);
        int num = egaddressmapper.insertadd(egaddress);
        if (num > 0) {
            return "添加成功";
        }
        return "添加失败";
    }

    @GetMapping("/list")
    public List<AddressListVO>list(){
        List<AddressListVO> addressInfoVOS = egaddressmapper.listadd();
        return addressInfoVOS;
    }

    @PostMapping("/del/{addressId}")
    public String del(){
       int num = egaddressmapper.delectadd();
       if(num>0){
           return "删除成功";
       }
        return "删除失败";
    }





}
